import { ALL, TODAY } from "../constants"
import { BaseFormType } from "../types"

export const deduplicationList = <T extends { id?: string }>(list: T[]) => {
    // 根据id去重
    const map = new Map()
    const result: T[] = []
    list.forEach((item) => {
        if (!map.has(item.id)) {
            map.set(item.id, true)
            result.push(item)
        }
    })
    return result
}

export const getFormData = ({ type, time_flag }: BaseFormType) => {
    if (type === ALL) {
        type = undefined
    }

    return {
        type,
        time_flag,
        status: type,
    }
}

export const getURLSearchParams = (params: URLSearchParams) => {
    const type = params.get("type") || ALL
    const time_flag = params.get("time_flag") || TODAY
    return {
        type,
        time_flag,
    }
}
